﻿@{
    Layout = null; 
}

<!DOCTYPE html>
<html>
<head>
    <title>ZTREE DEMO - checkbox</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <script src="~/Source/ztree/js/jquery-1.4.4.min.js"></script>
    @*<link href="~/Source/ztree/css/demo.css" rel="stylesheet" />
    <link href="~/Source/ztree/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" />
    <script src="~/Source/ztree/js/jquery-1.4.4.min.js"></script>
    <script src="~/Source/ztree/js/jquery.ztree.core.js"></script>
    <script src="~/Source/ztree/js/jquery.ztree.excheck.js"></script>*@
    <style>
        .tdClass {
            padding-left: 20px;
        }
    </style>

    <script>
        $(function () {
            $("#btnOK").click(function() {
                var MenuIds = "";
                $("input[name='chkMenu']:checked").each(function(i,e) {
                    MenuIds += $(e).val() + ",";
                });
                $.post("/Mechanism/InsertMenu", { "Ids": MenuIds,"RoleId":@ViewBag.RoleId }, function(returnData) {
                    console.log(returnData)
                    if(returnData){
                        alert("操作成功！");
                    }else{
                        alert("操作失败！");
                    }
                });
            });
        });
    </script>

</head>


<body>
    <div class="content_wrap">
        @*<div class="zTreeDemoBackground left" style="width: 100%">
            <ul id="treeDemo" class="ztree" style="width: 100%">
            </ul>
        </div>*@

        <table>
            <thead>
                <tr>
                    <td>
                        @*<input type="checkbox" name="name" />*@

                    </td>
                    @*<th>菜单编号</th>*@
                    <th>名称</th>
                    <th>路径</th>
                </tr>
            </thead>
            <tbody>
                @{
                    var list = BLL.MenusManager.QueryList().OrderBy(m => m.OrderIndex).ToList();
                    var authorList = ViewBag.authorList as List<Model.OA_Menus>;
                    bool IsOk = false;

                    if (list.Count != 0)
                    {
                        foreach (var item in list)
                        {
                             

                    <tr data-value="@item.IsParent">
                        <td>
                            @if (authorList.Count != 0)
                            {
                                foreach (var i in authorList)
                                {
                                    if (item.Id == i.Id)
                                    {
                                        IsOk = true;
                                        break;
                                    }
                                    else
                                    {
                                        IsOk = false;
                                    }

                                }
                                if (IsOk)
                                {
                                <input type="checkbox" name="chkMenu" checked="checked" value="@item.Id" />
                                }
                                else
                                {
                                <input type="checkbox" name="chkMenu" value="@item.Id" />
                                }

                            }
                            else
                            {
                                <input type="checkbox" name="chkMenu" value="@item.Id" />
                            }
                        </td>
                        <td>@item.Name</td>
                        <td>@item.Url</td>
                    </tr> 
                        }
                    }  
                }
            </tbody>
        </table>
        <input type="button" name="name" value="确定" id="btnOK" />
    </div>
</body>
</html>
@*<script type="text/javascript">
		<!--
    var setting = {
        check: {
            enable: true
        },
        data: {
            simpleData: {
                enable: true
            }
        }
    };



    var code;

    function setCheck() {
        var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
        py = $("#py").attr("checked") ? "p" : "",
        sy = $("#sy").attr("checked") ? "s" : "",
        pn = $("#pn").attr("checked") ? "p" : "",
        sn = $("#sn").attr("checked") ? "s" : "",
        type = { "Y": py + sy, "N": pn + sn };
        zTree.setting.check.chkboxType = type;
        showCode('setting.check.chkboxType = { "Y" : "' + type.Y + '", "N" : "' + type.N + '" };');
    }
    function showCode(str) {
        if (!code) code = $("#code");
        code.empty();
        code.append("<li>" + str + "</li>");
    }

    $(document).ready(function () {
        var zNodes = [];
        $.post("/Mechanism/Query", {}, function (returnData) { 
            zNodes = eval(returnData);
            $.fn.zTree.init($("#treeDemo"), setting, zNodes);
            setCheck();
            $("#py").bind("change", setCheck);
            $("#sy").bind("change", setCheck);
            $("#pn").bind("change", setCheck);
            $("#sn").bind("change", setCheck);
        });
    })







</script>*@
